const pyramid = (char, rowNum, isDownward) => {
  const lines = [];
  for (let i=0; i < rowNum; i++) {
    const space = ' '.repeat(rowNum - i - 1);
    lines.push(space + char.repeat(i * 2 + 1));
  }
  if (isDownward) {
    lines.reverse();
  }
  return "\n" + lines.join("\n") + "\n";
}

console.log(pyramid("o", 4, true));